using UnityEngine;
using System;

namespace LFramework
{
    /// <summary>
    /// 池管理器
    /// </summary>
    public class PoolManager : IDisposable
    {
        /// <summary>
        /// 类对象池
        /// </summary>
        public ClassObjectPool ClassObjectPool { get; private set; }

        /// <summary>
        /// 变量对象池
        /// </summary>
        public VarObjectPool VarObjectPool {  get; private set; }

        /// <summary>
        /// unity 物体对象池
        /// </summary>
        public GameObjectPool GameObjectPool { get; private set; }

        /// <summary>
        /// unity物体对象的容器
        /// </summary>
        private GameObject m_GameObjectPoosParent;
        public GameObject GameObjectPoosParent { 
            get 
            {
                if (m_GameObjectPoosParent == null) 
                {
                    m_GameObjectPoosParent = new GameObject("GameObjectPool");
                    m_GameObjectPoosParent.transform.parent = GameEntry.Instance.gameObject.transform;
                    m_GameObjectPoosParent.transform.localPosition = Vector3.zero;
                }
                return m_GameObjectPoosParent;
            }
        }

        internal PoolManager()
        {
            ClassObjectPool = new ClassObjectPool();
            VarObjectPool = new VarObjectPool();
            GameObjectPool = new GameObjectPool();
        }

        internal void OnUpdate()
        {
            ClassObjectPool.OnUpdate();
        }

        public void Dispose() 
        {
            ClassObjectPool.Dispose();
            GameObjectPool.Dispose();
        }
    }
}